package demo.threadpool;

public class WorkerThread extends Thread{
	
	private ThreadPool pool;
	
	private Job job;
	
	public WorkerThread(ThreadPool pool) {
		this.pool = pool;
	}
	
	@Override
	public synchronized void run() {
		System.out.println(this.getName() + "启动");
		while(true){
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
				this.isInterrupted();
			}
			
			System.out.println(this.getName() + "开始工作");
			
			if(job == null)
				return;
			
			job.make();
			
			this.job = null;
			
			this.pool.returnWorker(this);
		}
	}
	
	public synchronized void setJob(Job job){
		this.job = job;
		this.notify();
	}
}
